package com.igeek.util;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class MyException implements HandlerExceptionResolver{

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object arg2,
			Exception exception) {
		String msg;
		
//		if (exception instanceof MyException) {
//			msg =exception.getMessage();
//		}
		//运行异常， 读取错误堆栈信息；
		Writer out = new StringWriter();
		PrintWriter s = new PrintWriter(out);
		exception.printStackTrace(s);
		msg= out.toString();
		//吧错误信息发给相关人员，邮件，短信的方式。
		//返回错误页面， 给用户友好页面显示错误信息。
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("msg",msg);
		modelAndView.setViewName("error");
		
		return modelAndView;
	}

}
